﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

using System.Diagnostics; // Process 사용
using System.Threading;   // Timer 사용

namespace AFT
{    
     /* Android System Log Loader
     * 
     * 
     * 
     * 
     * 
     * 
     * 
     * 
     * 
     * 
     */
    class AndroidSystemLogLoader
    {
        String a11;
        Process pr1;

        private void cmdProcess_Exited(object sender, System.EventArgs e)
        {
            //pr1.StandardOutput.ReadToEnd();
            MessageBox.Show("asdf");
            //MessageBox.Show(a11);
        }


        public void RunADB(string job)
        {

            //eventhandler1 = false;
            
            /*
            pr1 = new Process();
            pr1.StartInfo.WorkingDirectory = "C:\\Program Files\\Android\\android-sdk\\platform-tools";
            pr1.StartInfo.FileName = "adb.exe"; // 프로그램 실행 커맨드
            pr1.StartInfo.Arguments = job; // 프로그램 실행용 추가 인자

            pr1.StartInfo.WindowStyle = ProcessWindowStyle.Normal;  // dos command 창을 열고 실행한다.
            // pr1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;  // dos command 창을 열지않고 실행한다.

            
            pr1.Exited += new EventHandler(cmdProcess_Exited); // 프로그램 종료 이벤트에 cmdProcess_Exited 메소드 추가
            //pr1.StartInfo.RedirectStandardOutput = true;
            
            pr1.Start();
            // a11 = pr1.StandardOutput.ReadToEnd();
            /*
            while (!pr1.StandardOutput.EndOfStream)
            {
                a11 += pr1.StandardOutput.ReadLine();
                // do something with line
            }
            /*
            /*
                while ((a11 = pr1.StandardOutput.ReadLine()) != null)
                {
                    MessageBox.Show(a11);
                }
            */


            
            Process process = new Process();
            process.StartInfo.WorkingDirectory = "C:\\Program Files\\Android\\android-sdk\\platform-tools";
            process.StartInfo.FileName = "adb.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            process.StartInfo.CreateNoWindow = true;
            //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.EnableRaisingEvents = true;
            process.StartInfo.Arguments = job;
            process.Exited += new EventHandler(cmdProcess_Exited);           
            
            //process.Start();
            

            process.Start();

            do
            {
                a11 = process.StandardOutput.ReadLine();
            } while (a11 != null);
            
            MessageBox.Show(a11);
            
        }
    }

}
